package com.oss.core;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 王霄
 * @date 2022/8/29 15:35
 */
@Configuration
@EnableConfigurationProperties(value = {OssProperties.class})
public class OssConfig {

    @Bean
    public OSS oss(OssProperties ossProperties) {
        return new OSSClientBuilder().build(ossProperties.getEndpoint(),
                ossProperties.getAccessKey(),
                ossProperties.getAccessSecret());
    }

    @Bean
    public OssClient ossClient(OSS oss, OssProperties ossProperties) {
        return new OssDefaultClient(oss, ossProperties);
    }

}
